$(document).ready(function () {
    //时间初始化
    $("div#list div.query form input[name='Start']").val($.getDate(0, -1));
    $("div#list div.query form input[name='End']").val($.getCurrentDate());
    window.update = function (X) {
        var H = $("div#list table.list tbody");
        var T = X;
        H.empty();
        var R = "</td><td>";
        if (T && T.length > 0) {
            var I = 0,
				K = 0,
				W = 0,
				B = 0,
				E = 0,
				Q = 0,
				U = 0;
            for (var V = 0; V < T.length; V++) {
                var D = T[V];
                var A = D.Num || 0;
                I += A;
                var M = D.Holidays || 0;
                K += M;
                var G = D.ServicePrice || 0;
                var J = (A + 2 * M) * G;
                W += J;
                var F = D.Discount || 1;
                var C = D.Adjust || 0;
                var O = D.Charge || 0;
                B += O;
                var P = D.Prepay || 0;
                //结算小计
                var subTotal = D.Pay || 0;
                E += subTotal;
                //结算调整
                var payAdjust = D.PayAdjust || 0;
                Q += payAdjust;
                //管理费
                var manageCost = O - subTotal;
                U += manageCost;
                //结算支出
                var settlePay = subTotal + payAdjust;
                H.append("<tr><td>" + D.Area + R + D.Bed + R + D.CustomerName + R + D.Category + R + D.ServiceName + R + D.Start + R + D.End + R + A + R + M + R + D.Invoice + R + D.BillSigner + R + D.ReceiptType + R + (D.ReceiptNo || "") + R + D.Company + R + G + R + J + R + F + R + C + R + O + R + P + R + subTotal + R + payAdjust + R + settlePay + R + manageCost + R + (D.Note || "") + "</td></tr>");
            }
            H.append('<tr><td colspan="2">合计</td><td>' + T.length + "人</td><td></td><td></td><td></td><td></td><td>" + I + R + K + R + R + R + R + R + R + R + W + R + R + R + B + R + R + E + R + Q + R + (E + Q) + R + U + "</td></tr>");
        } else {
            H.append('<tr><td colspan="30">没有相关记录信息</td></tr>');
        }
    };
    $("div#list div.query button.query").click(function (A) {
        query($("div#list div.query form").serializeParam(), "QueryRevenue");
        return false;
    });
    query($("div#list div.query form").serializeParam(), "QueryRevenue");

    $("div#list div.query button.export").click(function () {
        var params = $("div#list div.query form").serializeParam();
        $.ajax({
            url: "../Export/QueryRevenue",
            dataType: "json",
            data: params,
            timeout: timeout,
            success: function (rep) {
                if (rep.Result) {
                    $.downloadFile('../Export/Download', 'post', rep.Message);
                } else {
                    alert(rep.Message);
                }
            }
        }).fail(function (T, S) {
            alert("浏览器超时未响应，请刷新重试");
        });
        return false;
    });
});